package com.ftg.learn.chapter09.io;

import java.io.*;

/**
 * io文件操作
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/8/21 下午2:12
 */
public class IoFile {

    public static void main(String[] args) {
        File f1 = new File("/home/kangjx/Desktop/xyz.txt");
        if(!f1.exists()){
            try {
                f1.createNewFile();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

//        input  :  输入 java
//        output :  java 写到文件里

        String str = "this is my first io file";
        OutputStream os = null;
        try {
            os = new FileOutputStream(f1);


            char[] c = str.toCharArray();

            for (int i = 0; i < c.length; i++) {
                os.write(c[i]);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                os.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        //把java里面的内容输出到文件里面  输出
        //把文件里内容读取到java里叫输入

    }

}
